/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JPanel;

/**
 * Az idődiagram rajzát megjelenítő panel.
 * @author Kéki
 */
public class OscDrawJPanel extends JPanel {

    public boolean [] seq;

    /**
     * Az OnPaint esemény hatására hívódik, kirajzolja az idődiagramot a képernyőre.
     * @param g A Graphics objektum referenciája, amelyre rajzolunk.
     */
    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        int ox = 20;
        int oy = 45;
        //Tengelyek
        g.drawLine(ox, oy, ox, oy - 40);
        g.drawLine(ox, oy, ox + 405, oy);
        //Skála
        for (int i = 0; i <= 20;  i++)
            g.drawLine(ox + i * 20, oy + 3, ox + i * 20, oy - 3);
        g.drawString(Integer.toString(seq.length > 20 ? seq.length - 20 : 0), ox - 5, oy + 15);
        g.drawString(Integer.toString(seq.length > 20 ? seq.length : 20), ox + 400 - 5, oy + 15);
        //Nyil kirajzolása
        g.drawLine(ox + 10, oy + 8, ox + 50, oy + 8);
        int xcoord[] = {ox+50,ox+55,ox+50};
        int ycoord[] = {oy+5,oy+8,oy+11};
        g.fillPolygon(xcoord,ycoord,3);
        g.drawString("t", ox + 25, oy + 20);
        //Jelalak
        g.setColor(Color.blue);
        for(int i = 0, j = seq.length > 20 ? seq.length - 20 : 0; j < seq.length; i++, j++){
            //Ha a jel 1
            if (seq[j])
                g.drawLine(ox + i * 20, oy - 20, ox + (i + 1) * 20, oy - 20);
            //Ha 0
            else
                g.drawLine(ox + i * 20, oy, ox + (i + 1) * 20, oy);
            //Ha változik 0 és 1 között
            if ((j < seq.length -1) && (seq[j] ^ seq[j + 1])){
                g.drawLine(ox + (i + 1) * 20, oy - 20,ox + (i + 1) * 20, oy);
            }
        }

        g.setColor(Color.black);
    }
}
